package pl.vanta.utils.commons.validators.impl;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;

import pl.vanta.utils.commons.validators.AbstractValidator;

public class RegexpValidator extends AbstractValidator<String>
{
	private final Pattern	pattern;

	public RegexpValidator(String regexp)
	{
		this.pattern = Pattern.compile(regexp);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<String> validateWithErrors(String string)
	{
		if(string == null)
		{
			return Collections.singletonList("Parameter cannot be null");
		}
		
		if (this.pattern.matcher(string).matches())
		{
			return Collections.EMPTY_LIST;
		}
		else
		{
			return Arrays.asList(new String[] { "Podany ciag nie pasuje do wzorca" });
		}
	}
}